<template>
  <div>
    <el-table
      :data="lista"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="分类编号"> </el-table-column>
      <el-table-column prop="catename" label="分类名称" width="180">
      </el-table-column>
      <el-table-column label="图片">
        <template slot-scope="scope">
        
            <img :src="$pre+scope.row.img" class="photo" alt="">
          
        </template>
        
      </el-table-column>

      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1" type="success">启用</el-tag>
          <el-tag v-else type="info">未启用</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="150px">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="edit(scope.row.id)"
            >编辑</el-button
          >

          <el-button type="danger" size="small" @click="del(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { reqcatedelete } from "../../../request/api";
import { successAlert } from "../../../utils/alert";
import { mapActions, mapGetters } from "vuex";
export default {

  data() {
    return {
      list: [],
    };
  },
  created() {},
  mounted() {
    this.reqlist();

  },
  computed: {
    ...mapGetters({
      lista: "cate/list",
    }),
  },
  methods: {
    ...mapActions({
      reqlist: "cate/reqlist",
    }),
    del(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          reqcatedelete({ id: id }).then((res) => {
            if (res.data.code == 200) {
              // 如果删除弹出删除成功
              successAlert(res.data.msg);
              // 提醒父组件重新加载列表页面
              this.reqlist()
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    edit(id) {
      this.$emit("edit", id);
    },
  },
};
</script>

<style scoped >
.photo{
  width: 80px;
  height: 80px;
}
</style>
